﻿/*
 * Last review by   : Yaser
 * Last review date : JUL-25-09 
 */
using System.Collections;
using ERP.Framework.Components.Utilities.TracingHelper;

namespace ERP.Framework.Components.SortingHelper
{
    /// <summary>
    /// Sorting manager
    /// </summary>
    public abstract class SortingManager
    {
        #region Constructors

        /// <summary>
        /// Initializes the <see cref="SortingManager"/> class.
        /// </summary>
        static SortingManager()
        {
            CurrentSortAlgorithm = Interfaces.SortingAlgorithm.Quick;
        }

        #endregion

        #region Members

        private const string TRACING_CATEGORY = "ERP.Framework.Components.SortingHelper.SortingManager";
        private const string SORTING_ALGORITH_KEY = "SortingAlgorithm";

        #endregion

        #region Properties

        /// <summary>
        /// Gets or sets the current sort algorithm.
        /// </summary>
        /// <value>The current sort algorithm.</value>
        public static Interfaces.SortingAlgorithm CurrentSortAlgorithm
        {
            get;
            private set;
        }

        #endregion

        #region Methods

        /// <summary>
        /// Sorts the list.
        /// </summary>
        /// <param name="array">The array.</param>
        public static void SortList(IList array)
        {
            TraceUtil.Write(TRACING_CATEGORY, "SortList : Start");
            switch (CurrentSortAlgorithm)
            {
                case Interfaces.SortingAlgorithm.Shell:
                    ShellSortHelper.SortList(array);
                    break;
                case Interfaces.SortingAlgorithm.Quick:
                    QuickSortHelper.SortList(array);
                    break;
                default:
                    QuickSortHelper.SortList(array);
                    break;
            }
            TraceUtil.Write(TRACING_CATEGORY, "SortList : End");
        }

        #endregion
    }
}